package exec567;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test {



    public static List<Student> getStudent(){
        Student student=null;
        List<Student> students =new ArrayList<>();

        Scanner scanner=new Scanner(System.in);
        String code=null;
        String stuName=null;
        SEX sex=null;
        int score=0;
        String strY="";
        while(true){
            System.out.println("输入学生的学号：");
            code=scanner.next();
            System.out.println("输入学生的姓名：");
            stuName=scanner.next();
            System.out.println("输入学生的性别(输入0/1)：");
            int sexInt=scanner.nextInt();
            sex=sexInt==0?SEX.MAN:SEX.WOMAN;
            System.out.println("输入学生的分数：");
            score=scanner.nextInt();
            student =new Student();
            student.setCode(code);
            student.setStuName(stuName);
            student.setSex(sex);
            student.setScore(score);
            students.add(student);

            System.out.println("是否继续添加学生（y/n）");
            strY=scanner.next();
            if(!"y".equals(strY)){
                break;
            }
        }
        return students;
    }

    public static void main(String[] args) {
        List<Student> list=getStudent();
        File file=new File("student.dat");
        try {
            OutputStream out=new FileOutputStream(file,true);
            ObjectOutputStream outputStream=new ObjectOutputStream(out);
            outputStream.writeObject(list);
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
